package com.crx.springbootinit.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crx.springbootinit.annotation.AuthCheck;
import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.dto.post.PostDto;
import com.crx.springbootinit.model.dto.post.PostOtherPageDTO;
import com.crx.springbootinit.model.dto.post.PostPageDTO;
import com.crx.springbootinit.model.dto.post.PostUserPageDTO;
import com.crx.springbootinit.model.entity.Post;
import com.crx.springbootinit.model.vo.post.PostListVO;
import com.crx.springbootinit.model.vo.post.PostPageVO;
import com.crx.springbootinit.model.vo.post.PostVO;
import com.crx.springbootinit.service.IPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user/post")
@RequiredArgsConstructor
@Api(tags = "帖子模块接口")
public class PostController {
    @Autowired
    private IPostService postService;

    /**
     * 新增帖子
     * @param postDto
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation("新增帖子")
    @LogApiAnno(title = "帖子模块", businessType = "POST")
    public BaseResponse addPost(@RequestBody PostDto postDto) {
        postService.addPost(postDto);
        return ResultUtils.success(null);
    }

    /**
     * 游玩帖子
     * @param postId
     * @return
     */
    @GetMapping("/playPost")
    @ApiOperation("游玩帖子")
    @LogApiAnno(title = "帖子模块", businessType = "GET")
    public BaseResponse<Post> playPost(Long postId) {
        Post post = postService.playPost(postId);
        // 模拟用户点击“游玩”后返回成功响应
        return ResultUtils.success(post);
    }

    /**
     * 获取帖子列表
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("获取帖子列表")
    @LogApiAnno(title = "帖子模块", businessType = "GET")
    public BaseResponse<List<PostListVO>> listPosts(HttpServletRequest request, @RequestBody PostUserPageDTO postUserPageDTO) {
        String token = request.getHeader("token");
        List<PostListVO> posts = postService.listPosts(token,postUserPageDTO);
        return ResultUtils.success(posts);
    }

    /**
     * 帖子详细信息
     * @param postId 帖子Id
     * @return
     */
    @GetMapping("/getPostById")
    @ApiOperation("获取帖子详情")
    @LogApiAnno(title = "帖子模块", businessType = "GET")
    public BaseResponse<PostVO> getPostById(HttpServletRequest request,@RequestParam Long postId) {
        String token = request.getHeader("token");
        PostVO postVO = postService.getPostById(token,postId);
        return ResultUtils.success(postVO);
    }
}
